#include "ownerinfo.h"
#include "ui_ownerinfo.h"

OwnerInfo::OwnerInfo(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::OwnerInfo)
{
    ui->setupUi(this);

    TelBox = QSqlDatabase::addDatabase("QMYSQL");
    TelBox.setHostName("localhost");
    TelBox.setUserName("root");
    TelBox.setPassword("");
    TelBox.setDatabaseName("petmanage");
}

OwnerInfo::~OwnerInfo()
{
    delete ui;
}

void OwnerInfo::on_QueryTel_clicked()
{
    QString OwnID = ui->IDInput->text();

    if (OwnID.isEmpty()) {
        QMessageBox::warning(this, "输入错误", "请输入要查询的OwnID！");
        return;
    }

    TelModel = new QSqlTableModel;
    TelModel->setQuery(QString("SELECT * FROM OwnerInfo WHERE OwnerID = %1").arg(OwnID));

    if (TelModel->rowCount() == 0) {
        QMessageBox::information(this, "查询结果", "未找到该OwnerID对应的记录！");
        ui->IDInput->clear();
        delete TelModel;
        return;
    }

    ui->tableView->setModel(TelModel);

    /*查询成功后清除文本框输入内容*/
    ui->IDInput->clear();
}

